<template>
  <div>
    <i v-if='value===-1' :class="value === 0 ? 'toutiao toutiao-cai-f' : 'toutiao toutiao-cai-l'"></i>
    <van-icon :color="value === 1 ?'red':'#777'" name='good-job-o' @click='onliking' />
  </div>
</template>

<script>
// 点赞文章请求 取消点赞文章请求
import { addArticleLike, deleteArticleLike } from '@/api/article'
export default {
  data () {
    return {}
  },
  props: {
    value: {
      type: Number,
      required: true
    },
    articleId: {
      tyep: [Object, Number],
      required: true
    }
  },
  methods: {
    async onliking () {
      try {
        if (this.value === 1) {
          await deleteArticleLike(this.articleId)
          this.$emit('input', -1)
          this.$toast('取消点赞')
        } else {
          await addArticleLike(this.articleId)
          this.$emit('input', 1)
          this.$toast('点赞成功')
        }
      } catch (err) {
        this.$toast('操作失败')
      }
    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: {},
  created () {

  },
  mounted () { }
}
</script>

<style scoped lang='less'>
.van-toast {
  font-size: 20px;
}
</style>
